#!/bin/sh
#
# This is the script for generating files for a specific Dalton test job.
#
# For the .check file ksh or bash is preferred, otherwise use sh
# (and hope it is not the old Bourne shell, which will not work)
#
if [ -x /bin/ksh ]; then
   CHECK_SHELL='#!/bin/ksh'
elif [ -x /bin/bash ]; then
   CHECK_SHELL='#!/bin/bash'
else
   CHECK_SHELL='#!/bin/sh'
fi
 

#######################################################################
#  TEST DESCRIPTION
#######################################################################
cat > rsp_ctocdhyper.info <<%EOF%
   rsp_ctocdhyper
   --------------
   Molecule:         H2O
   Wave Function:    SCF
   Test Purpose:     Calculation of CTOCD-DZ diamagnetic part of
   		     hypermagnetizability through RESPONSE
%EOF%

#######################################################################
#  MOLECULE INPUT
#######################################################################
cat > rsp_ctocdhyper.mol <<%EOF%
INTGRL
Calculation of CTOCD-DZ diamagnetic part of the hypermagnetizability
through RESPONSE
c   2    2  X  Y      0.10D-15  0.10D-15
      8.00    1    3    6    5    1
O   0.00000             0.00000              0.1241444240
F  6    1
31195.6 0.00021
4669.38 0.001628
1062.62 0.00845
301.426 0.034191
98.5153 0.110311
35.4609 .269493
F  1    1
13.6179 .423545
F  1    1
5.38618 .283038
F  1    1
1.53873 .027484
F  1    1
.6055 -.005144
F  1    1
.22054 .00164
F  3    1
114.863 .002266
26.8767 0.017192
8.32077 0.075341
F  1    1
2.97237 .212775
F  1    1
1.12848 .370478
F  1    1
.4236 .398523
F  1    1
.15074 .184703
F  2    1
1.21879 .357851
.36102 .759561
      1.00    1    2    3    1
H   0.00000             1.43153              -0.985265576
F  3    1
33.865014 .006068
5.094788 0.045316
1.158786 0.202846
F  1    1
0.32584 0.503709
F  1    1
.102741 .383568
F  1    1
1.16 1.0
%EOF%

#######################################################################
#  DALTON INPUT
#######################################################################
cat > rsp_ctocdhyper.dal <<%EOF%
**DALTON INPUT
.RUN RESPONSE
**INTEGRALS
.DIPVEL
.DIPLEN
.RANGMO
**WAVE FUNCTION
.HF
**RESPONSE
*QUADRATIC
.BPROP
XDIPLEN
.BPROP
YDIPLEN
.BPROP
ZDIPLEN
.APROP
XDIPVEL
.APROP
YDIPVEL
.APROP
ZDIPVEL
.CPROP
XXRANG
.CPROP
XYRANG
.CPROP
XZRANG
.CPROP
YXRANG
.CPROP
YYRANG
.CPROP
YZRANG
.CPROP
ZXRANG
.CPROP
ZYRANG
.CPROP
ZZRANG
**END OF DALTON INPUT
%EOF%
#######################################################################



#######################################################################

#######################################################################
#  CHECK SCRIPT
#######################################################################
echo $CHECK_SHELL >rsp_ctocdhyper.check
cat >>rsp_ctocdhyper.check <<'%EOF%'
log=$1

if [ `uname` = Linux ]; then
   GREP="egrep -a"
else
   GREP="egrep"
fi

# Basis set
CRIT1=`$GREP "O * 1 * 8\.0000 * 44 * 27 * \[11s7p2d\|6s5p1d\]" $log | wc -l`
CRIT2=`$GREP "H * 2 * 1\.0000 * 8 * 6 * \[5s1p\|3s1p\]" $log | wc -l`
CRIT3=`$GREP "total\: * 3 * 10\.0000 * 60 * 39" $log | wc -l`
CRIT4=`$GREP "Cartesian basis used" $log | wc -l`
TEST[1]=`expr	$CRIT1 \+ $CRIT2 \+ $CRIT3 \+ $CRIT4`
CTRL[1]=4
ERROR[1]="BASIS SET NOT READ CORRECTLY"

# Geometry
CRIT1=`$GREP "Total number of coordinates\: * 9" $log | wc -l`
CRIT2=`$GREP "1 * x * (0| )\.0000000000" $log | wc -l`
CRIT3=`$GREP "2 * y * (0| )\.0000000000" $log | wc -l`
CRIT4=`$GREP "3 * z * (0| )\.1241444240" $log | wc -l`
CRIT5=`$GREP "4 * x * (0| )\.0000000000" $log | wc -l`
CRIT6=`$GREP "5 * y * 1\.4315300000" $log | wc -l`
CRIT7=`$GREP "6 * z * (\-0|\-)\.9852655760" $log | wc -l`
CRIT8=`$GREP "7 * x * (0| )\.0000000000" $log | wc -l`
CRIT9=`$GREP "8 * y * \-1\.4315300000" $log | wc -l`
CRIT10=`$GREP "9 * z * (\-0|\-)\.9852655760" $log | wc -l`
TEST[2]=`expr	$CRIT1 \+ $CRIT2 \+ $CRIT3 \+ $CRIT4 \+ $CRIT5 \+ $CRIT6 \+ \
		$CRIT7 \+ $CRIT8 \+ $CRIT9 \+ $CRIT10`
CTRL[2]=10
ERROR[2]="GEOMETRY NOT READ CORRECTLY"

# Symmetry
CRIT1=`$GREP "Number of coordinates in each symmetry\: * 3 * 2 * 3 * 1" $log | wc -l`
CRIT2=`$GREP "Number of orbitals in each symmetry\: * 19 * 7 * 11 * 2" $log | wc -l`
TEST[3]=`expr	$CRIT1 \+ $CRIT2`
CTRL[3]=2
ERROR[3]="SYMMETRY NOT CORRECT"

# Energies
CRIT1=`$GREP "Final * HF energy\: * \-76\.06078421[89]" $log | wc -l`
TEST[4]=`expr	$CRIT1`
CTRL[4]=1
ERROR[4]="ENERGIES NOT CORRECT"

# Linear Response Results
#CRIT1=`$GREP "ZDIPVEL  \; XYRANG   >> \(   (0| )\.0000[0-9]\)\:    \-4\.7034873308[0-9]" $log | wc -l`    
#CRIT2=`$GREP "ZDIPVEL  \; YXRANG   >> \(   (0| )\.0000[0-9]\)\:     5\.9485583150[0-9]" $log | wc -l`    
#CRIT3=`$GREP "XYRANG   \; ZDIPVEL  >> \(   (0| )\.0000[0-9]\)\:    \-4\.7033926009[0-9]" $log | wc -l`    
#CRIT4=`$GREP "YXRANG   \; ZDIPVEL  >> \(   (0| )\.0000[0-9]\)\:     5\.9485892146[0-9]" $log | wc -l`    
#CRIT5=`$GREP "YZRANG   \; XDIPVEL  >> \(   (0| )\.0000[0-9]\)\:    \-5\.5766088261[0-9]" $log | wc -l`    
#CRIT6=`$GREP "ZYRANG   \; XDIPVEL  >> \(   (0| )\.0000[0-9]\)\:     4\.9882614160[0-9]" $log | wc -l`    
#CRIT7=`$GREP "XDIPVEL  \; YZRANG   >> \(   (0| )\.0000[0-9]\)\:    \-5\.5766705607[0-9]" $log | wc -l`    
#CRIT8=`$GREP "XDIPVEL  \; ZYRANG   >> \(   (0| )\.0000[0-9]\)\:     4\.9884313935[0-9]" $log | wc -l`    
#CRIT9=`$GREP "XZRANG   \; YDIPVEL  >> \(   (0| )\.0000[0-9]\)\:     5\.0395815681[0-9]" $log | wc -l`    
#CRIT10=`$GREP "ZXRANG   \; YDIPVEL  >> \(   (0| )\.0000[0-9]\)\:    \-5\.7022184236[0-9]" $log | wc -l`    
#CRIT11=`$GREP "YDIPVEL  \; XZRANG   >> \(   (0| )\.0000[0-9]\)\:     5\.0398617210[0-9]" $log | wc -l`    
#CRIT12=`$GREP "YDIPVEL  \; ZXRANG   >> \(   (0| )\.0000[0-9]\)\:    \-5\.7028485787[0-9]" $log | wc -l`    
#TEST[5]=`expr $CRIT1 \+ $CRIT2 \+ $CRIT3 \+ $CRIT4 \+ $CRIT5 \+ $CRIT6 \+ \
#              $CRIT7 \+ $CRIT8 \+ $CRIT9 \+ $CRIT10 \+ $CRIT11 \+ $CRIT12`
#ERROR[5]="LINEAR RESPONSE RESULTS NON CORRECT ${TEST[5]}"

# Quadratic Response
CRIT1=`$GREP "QR value \: * (0| )\.000[0-9]* * (0| )\.0000[0-9]* * \-1\.8796[0-9]*" $log | wc -l`
CRIT2=`$GREP "QR value \: * (0| )\.0000[0-9]* * (0| )\.0000[0-9]* * (\-0|\-)\.2149[0-9]*" $log | wc -l`
CRIT3=`$GREP "QR value \: * (0| )\.0000[0-9]* * (0| )\.0000[0-9]* * (\-0|\-)\.6155[0-9]*" $log | wc -l`
CRIT4=`$GREP "QR value \: * (0| )\.0000[0-9]* * (0| )\.0000[0-9]* * (0| )\.3179[0-9]*" $log | wc -l`
CRIT5=`$GREP "QR value \: * (0| )\.0000[0-9]* * (0| )\.0000[0-9]* * (\-0|\-)\.0518[0-9]*" $log | wc -l`
CRIT6=`$GREP "QR value \: * (0| )\.0000[0-9]* * (0| )\.0000[0-9]* * 1\.7859[0-9]*" $log | wc -l`
CRIT7=`$GREP "QR value \: * (0| )\.0000[0-9]* * (0| )\.0000[0-9]* * (\-0|\-)\.3466[0-9]*" $log | wc -l`
CRIT8=`$GREP "QR value \: * (0| )\.0000[0-9]* * (0| )\.0000[0-9]* * 2\.3944[0-9]*" $log | wc -l`
CRIT9=`$GREP "QR value \: * (0| )\.0000[0-9]* * (0| )\.0000[0-9]* * (0| )\.4170[0-9]*" $log | wc -l`
CRIT10=`$GREP "QR value \: * (0| )\.0000[0-9]* * (0| )\.0000[0-9]* * \-1\.8293[0-9]*" $log | wc -l`
CRIT11=`$GREP "QR value \: * (0| )\.0000[0-9]* * (0| )\.0000[0-9]* * (0| )\.6512[0-9]*" $log | wc -l`
CRIT12=`$GREP "QR value \: * (0| )\.0000[0-9]* * (0| )\.0000[0-9]* * (\-0|\-)\.0840[0-9]*" $log | wc -l`
CRIT13=`$GREP "QR value \: * (0| )\.0000[0-9]* * (0| )\.0000[0-9]* * (\-0|\-)\.0357[0-9]*" $log | wc -l`
CRIT14=`$GREP "QR value \: * (0| )\.0000[0-9]* * (0| )\.0000[0-9]* * (\-0|\-)\.0605[0-9]*" $log | wc -l`
CRIT15=`$GREP "QR value \: * (0| )\.0000[0-9]* * (0| )\.0000[0-9]* * (\-0|\-)\.2396[0-9]*" $log | wc -l`
CRIT16=`$GREP "QR value \: * (0| )\.0000[0-9]* * (0| )\.0000[0-9]* * (\-0|\-)\.111[12]*" $log | wc -l`
CRIT17=`$GREP "QR value \: * (0| )\.0000[0-9]* * (0| )\.0000[0-9]* * (0| )\.3506[0-9]*" $log | wc -l`
CRIT18=`$GREP "QR value \: * (0| )\.0000[0-9]* * (0| )\.0000[0-9]* * (0| )\.2044[0-9]*" $log | wc -l`
CRIT19=`$GREP "QR value \: * (0| )\.0000[0-9]* * (0| )\.0000[0-9]* * (\-0|\-)\.2484[0-9]*" $log | wc -l`
CRIT20=`$GREP "QR value \: * (0| )\.0000[0-9]* * (0| )\.0000[0-9]* * (0| )\.0435[0-9]*" $log | wc -l`
CTRL[6]=20
TEST[6]=`expr $CRIT1 \+ $CRIT2 \+ $CRIT3 \+ $CRIT4 \+ $CRIT5 \+ $CRIT6 \+ \
              $CRIT7 \+ $CRIT8 \+ $CRIT9 \+ $CRIT10 \+ $CRIT11 \+ $CRIT12 \+ \
              $CRIT13 \+ $CRIT14 \+ $CRIT15 \+ $CRIT16 \+ $CRIT17 \+ \
              $CRIT18 \+ $CRIT19 \+ $CRIT20`
ERROR[6]="QUADRATIC RESPONSE RESULTS NOT CORRECT ${TEST[6]}"

PASSED=1
for i in 1 2 3 4 6 
do
   if [ ${TEST[i]} -ne ${CTRL[i]} ]; then
     echo "${ERROR[i]} ( test = ${TEST[i]}; control = ${CTRL[i]} ); "
     PASSED=0
   fi
done

if [ $PASSED -eq 1 ]
then
  echo TEST ENDED PROPERLY
  exit 0
else
  echo THERE IS A PROBLEM
  exit 1
fi

%EOF%
#######################################################################
